<?php


namespace BoojasrFramework\Service;

use Symfony\Component\Console\Command\Command;

class CommandService
{
    /**
     * @var Command[]
     */
    private $commands;

    /**
     * @return Command[]
     */
    public function getCommands():array
    {
        return $this->commands;
    }

    /**
     * @param Command[] $commands
     */
    public function setCommands(array $commands): self
    {
        $this->commands = $commands;

        return $this;
    }

    /**
     * @param string|null $name
     * @return bool
     */
    public function hasCommand(?string $name):bool
    {
        return isset($this->commands[$name]);
    }

    /**
     * @param Command $command
     * @return CommandService
     */
    public function addCommand(Command $command):self
    {
        if ($this->hasCommand($command->getName())){
            return $this;
        }
        $this->commands[$command->getName()] = $command;
        return $this;
    }
}
